// pages/address/address.js
const app = getApp();

const allcity = require('../../utils/allcity.js');
Page({
  data: {
    cityGroup: allcity,
    isSearch: false,
    searchText: '',
    searchArrGroup: []
  },
  goback:function(){
    wx.navigateBack({
      delta: 1
    })
  },
  onLoad: function (options) {
    
  },
  // 搜索输入
  inputSearchText:function(e){
    this.setData({
      searchText: e.detail.value
    });
  },
  // 搜索
  searchCity:function(){
    let _cityGroup = this.data.cityGroup;
    let _searchText = this.data.searchText;
    let tempArr = [];
    _cityGroup.forEach(function(parentItem,index){
      parentItem.item.forEach(function(item,index){
        if (item.name.indexOf(_searchText, 0) >= 0){
          tempArr.push(item);
        }
      });
    });
    this.setData({
      isSearch: true,
      searchArrGroup: tempArr
    })
  },
  // 城市选择
  chooseCity:function(e){
    let cityName = e.currentTarget.dataset.name;
    app.data.address.name = cityName
    wx.navigateBack({})
  },
  onShow:function(){
    var that=this;
    that.setData({
      mycity:app.data.address.name
    })
  }
  
})